package com.excel.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.List;

import org.apache.poi.POIXMLDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class Excels {

	public static List<String> getSheetNames(String filePath)throws Exception{
		InputStream inp = null;
		try{
			inp = new PushbackInputStream(new FileInputStream(filePath), 8);
			if(POIFSFileSystem.hasPOIFSHeader(inp)) {
				return Excel2003.getSheetNames(inp);
			}	

			if(POIXMLDocument.hasOOXMLHeader(inp)) {
				return Excel2007.getSheetNames(inp);
			}

			throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
		}finally{
			if(inp != null){
				inp.close();
			}
		}
		
	}
	
			
}
